package ren.kane.asdppp.schedule;

import java.time.LocalDate;
import java.time.temporal.TemporalAdjusters;

/**
 * @author renrk(1275) on 2019-04-09 8:31 PM
 **/
public class MonthlySchedule implements PaymentSchedule {

    @Override
    public boolean isPayDate(LocalDate payDate) {
        return isLastDayOfMonth(payDate);
    }

    @Override
    public LocalDate getPayPeriodStartDate(LocalDate payPeriodEndDate) {
        return payPeriodEndDate.with(TemporalAdjusters.firstDayOfMonth());
    }

    private boolean isLastDayOfMonth(LocalDate payDate) {
        LocalDate lastDayOfMonth = payDate.with(TemporalAdjusters.lastDayOfMonth());
        return payDate.isEqual(lastDayOfMonth);
    }
}
